<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- ArcGIS API for JavaScript本地部署地址 -->
    <!-- <link rel="stylesheet" hrel="http://localhost/arcgis_js_v416_sdk/arcgis_js_api/library/4.16/esri/css/main.css" />
    <script src="http://localhost/arcgis_js_v416_sdk/arcgis_js_api/library/4.16/dojo/dojo.js"></script> -->

    <!-- jquery-2.0.3.min.js是jquery-2.0.3.js的编译版本 -->
    <!-- jQuery 库是一个 JavaScript 文件,下面在线引用它。 -->
    <!-- <script src="https://code.jquery.com/jquery-2.0.3.min.js"></script> -->
    <script src="js/jquery-2.0.3.min.js"></script>

    <link rel="stylesheet" href="https://js.arcgis.com/4.16/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.16/"></script>

    <!-- <link rel="stylesheet" hrel="http://localhost/4.16/esri/css/main.css" />
    <script src="http://localhost/4.16/dojo/dojo.js"></script> -->

    <style>
        .tool {
            width: 43.1px;
        }
        
        .drawDiv {
            width: 43.1px;
            height: 24.1px;
            border: 0.01px solid rgb(253, 25, 25);
            background-color: rgb(137, 13, 238);
            font: 15px "宋体";
        }
        
        .toolOptional {
            display: none;
        }
        
        .point1:hover {
            width: 43.1px;
            height: 24.1px;
            border: 2px solid rgb(250, 185, 5);
            background-color: rgb(139, 131, 251);
        }
        /* .drawbt:hover {
            background-color: green;
        }
        
        .drawbt:hover.toolOptional {
            display: inline-block;
        } */
    </style>
    <script>
        require([
            "esri/Map",
            "esri/Basemap",
            "esri/views/MapView",
            "esri/views/SceneView",
            "esri/geometry/Extent",
            "esri/geometry/SpatialReference",
            "esri/geometry/Point",
            "esri/geometry/Polyline",
            "esri/geometry/Polygon",
            "esri/Graphic",
            "esri/Color",
            "esri/views/layers/LayerView",
            "esri/layers/TileLayer",
            "esri/layers/MapImageLayer",
            "esri/layers/FeatureLayer",
            "esri/layers/GraphicsLayer",
            "esri/symbols/SimpleMarkerSymbol",
            "esri/symbols/SimpleFillSymbol",
            "esri/symbols/SimpleLineSymbol",
            "esri/tasks/support/BufferParameters",
            "esri/tasks/GeometryService",
            "esri/core/urlUtils",
            "esri/tasks/QueryTask",
            "esri/tasks/support/Query",
            "esri/tasks/IdentifyTask",
            "dojo/dom",
            "dojo/on",
            "dojo/domReady!"
        ], function(
            Map,
            Basemap,
            MapView,
            SceneView,
            Extent,
            SpatialReference,
            Point,
            Polyline,
            Polygon,
            Graphic,
            Color,
            LayerView,
            TileLayer,
            MapImageLayer,
            FeatureLayer,
            GraphicsLayer,
            SimpleMarkerSymbol,
            SimpleFillSymbol,
            SimpleLineSymbol,
            BufferParameters,
            GeometryService,
            urlUtils,
            QueryTask,
            Query,
            IdentifyTask,
            dom,
            on) {
            //创建一个地图Map实例
            var basemap = new Basemap({
                baseLayers: [
                    new MapImageLayer({
                        url: "http://www.fqghj.net:8022/arcgis/rest/services/CXGHBZ/YDGHPH/MapServer"
                    })
                ],
                title: "basemap",
                id: "basemap"
            });

            var layer = new MapImageLayer({
                url: "http://www.fqghj.net:8022/arcgis/rest/services/DG/CZKFBJ0614/MapServer"
            });
            var map = new Map({ //属性：allLayers、ground、layers
                basemap: basemap,
                layers: [layer]
            });
            //创建一个MapView实例（用于2D查看）并引用该地图实例
            //为了使地图在DOM中对用户可见，必须创建一个MapView并至少引用两个对象：一个Map实例和一个DOM元素。分别在map和container属性中设置。
            var view = new MapView({
                container: "viewDiv",
                map: map,
                zoom: 4,
                center: [55, 65] // longitude, latitude
            });
            view.ui.add("line-button", "top-left");

            function drawgeo() {
                var draw = new Draw({
                    view: view
                });
                var action = draw.create("polyline", {
                    mode: "click"
                });
                action.on("vertex-add", function(evt) {
                    measureLine(evt.vertices);
                });
                action.on("cursor-update", function(evt) {
                    measureLine(evt.vertices);
                });
                action.on("draw-complete", function(evt) {
                    measureLine(evt.vertices);
                });
                action.on("vertex-remove", function(evt) {
                    measureLine(evt.vertices);
                });

                function measureLine(vertices) {
                    view.graphic.removeAll();
                    var line = createLine(vertices);
                    var lineLength = geometryEngine.planarLength(line, "miles");
                    var graphic = createGraphic(line);
                    view.graphics.add(graphic);
                };
            };

            var dh = true;
            $(".drawbt").click(function() {
                if (dh) {
                    $(".toolOptional").css("display", "block");
                    dh = false;
                    $(this).css("background-color", "");

                } else {
                    $(".toolOptional").css("display", "none");
                    dh = true;
                    $(this).css("background-color", "#66ffff");
                }
            });
            $(".point1").click(function() {
                drawgeo();
            });
        });
    </script>
</head>

<body>
    <div id="viewDiv"></div>
    <!-- <div id="drawGraphic">绘制</div> -->
    <div class="tool">
        <div class="drawDiv">
            <button class="drawbt">绘制</button>
        </div>
        <div class="toolOptional">
            <div class="point1">点</div>
            <div class="line1">线</div>
            <div class="polygon1">面</div>
        </div>
    </div>

    <!-- <ul id="drawTool">
        <li>点</li>
        <li>线</li>
        <li>面</li>
        <li>圆</li>
        <li>矩形</li>
        <li>多边形</li>
    </ul> -->
</body>

</html>